import './detail.css';
import {connect} from 'react-redux';
import {Link} from 'react-router';
import Panel from './../../elements/Panel'
import {URL, md5Url} from '../../libs/Url';
import {Config} from '../../libs/';
import BreadcrumbNavigation from './../../components/BreadcrumbNavigation';

import {
    fetch,
    fetch_remove,
    enable_delete_btn,
    selectAllItem,
    selectItem,
} from '../../actions';
import {SUBJECT, PAGE_SUBJECT} from './../../actions/subject'
const Title = React.createClass({
    render(){
        return (
            <h1 className="text-center mtop35">{this.props.title}</h1>
        )
    }
});
const Des = React.createClass({
    render(){
        return (
            <p className="text-center auth-row">
                时间：{Moment(this.props.intime).format('YYYY-MM-DD HH:MM:ss')}
            </p>
        )
    }
});
const Detail = React.createClass({
    componentDidMount(){
        const {dispatch} = this.props;
        dispatch(fetch({url: URL.NOTICE_GET, announceid: this.props.params.id}));
    },
    render(){
        const news = this.props[md5Url.NOTICE_GET].announce || {};
        news.classList = (news.classList instanceof Array) ? news.classList : ['全部'];

        return (
            <div>
                <BreadcrumbNavigation navs={[
                    {url: Config.MENUS_ABSOLUTE.HOME, label: '首页'},
                    {url: Config.MENUS_ABSOLUTE.NOTICES, label: '通知列表'},
                    {label: '正文'},
                ]}></BreadcrumbNavigation>
                <Panel>
                    <div className="panel-body">
                        <Title {...news}></Title>
                        <Des {...news}/>
                        <div dangerouslySetInnerHTML={{__html: news.summary}}></div>
                        <div className="blog-tags">
                            推送到的班级： {
                            news.classList.map((item, index)=> {
                                return <span key={index}>{item.name}</span>
                            })
                        }
                        </div>
                    </div>
                </Panel>
            </div>
        )
    }
})
function select(state) {
    return {
        [md5Url.NOTICE_GET]: state.fetchBySubject[md5Url.NOTICE_GET],
    }
}
export default connect(select)(Detail)